module.exports = {
  array_diff(a,b) { 
    for(var i=0;i<b.length;i++) { 
      for(var j=0;j<a.length;j++) { 
         if(a[j]==b[i]){ 
         a.splice(j,1); 
         j=j-1; 
        } 
      } 
    } 
    return a; 
  },
   //将秒转化为时分秒
   formateSeconds(endTime){
    let secondTime = parseInt(endTime)//将传入的秒的值转化为Number
    let min = 0// 初始化分
    let h =0// 初始化小时
    let result=''
    if(secondTime>60){//如果秒数大于60，将秒数转换成整数
      min=parseInt(secondTime/60)//获取分钟，除以60取整数，得到整数分钟
      secondTime=parseInt(secondTime%60)//获取秒数，秒数取佘，得到整数秒数
      if(min>60){//如果分钟大于60，将分钟转换成小时
        h=parseInt(min/60)//获取小时，获取分钟除以60，得到整数小时
        min=parseInt(min%60) //获取小时后取佘的分，获取分钟除以60取佘的分
      }
    }
    return {h:h,m:min} 
  },
  //计算金额总数
  getPrice(data,key='price'){
    let x=0
    data.forEach(val=>{
      x+=Number(val[key])
    })
    return x
  },
  getMiStr(str){
   return str[0]+str[1]+'***'+str[str.length-4]+str[str.length-3]+str[str.length-2]+str[str.length-1]
  },
  
  //循环对象拼接字符串
  getStr(arr,symbol='、',name='name',name2=null){
       let str=''
       arr.forEach((val,index)=>{
          if(name2){
            if(index<arr.length-1){str+=(val[name][name2]+symbol)}else{str+=val[name]}
          }else{
           if(index<arr.length-1){str+=(val[name]+symbol)}else{str+=val[name]}
          }
       })
       if(str==''){
         return '--'
       }else{
         return str
       }
  },
  
  //组合Url一维数组
  getUrl(data){
    let arr=[]
    data.forEach(val => {
      arr.push(val.url)
    });
    return arr
  },
  //清空对象
  clearObj:function(obj){
		for(let i in obj){
			obj[i]='' 
		}
	},
  // 获取当前时间
	currentTime : function (returnType, addVal) {
		var dateObj = new Date();
		var cTime = dateObj.getTime();
		if(addVal){cTime += addVal;}
		if(!returnType){return cTime;}
		return this.formatDateTime(cTime / 1000, 'str');
  },
  formatDate: function(str, t) {
		if (!t) {t=this.currentTime()};
		var d = new Date(t.toString().length == 10 ? t * 1000 : t);
		var _m = d.getMonth() + 1,
			_d = d.getDate(),
			_H = d.getHours(),
			_i = d.getMinutes(),
			_s = d.getSeconds(),
			format = {
				'Y': d.getFullYear(), // 年
				'm': _m.toString().length == 1 ? '0' + _m : _m, // 月
				'd': _d.toString().length == 1 ? '0' + _d : _d, // 日
				'H': _H.toString().length == 1 ? '0' + _H : _H, // 时
				'i': _i.toString().length == 1 ? '0' + _i : _i, // 分
				's': _s.toString().length == 1 ? '0' + _s : _s // 秒
			};
		for (var i in format) {
			str = str.replace(new RegExp(i), format[i]);
		}
		return str;
  },
  deep:function (obj) {
	  //判断拷贝的要进行深拷贝的是数组还是对象，是数组的话进行数组拷贝，对象的话进行对象拷贝
	  var objClone = Array.isArray(obj) ? [] : {};
	  //进行深拷贝的不能为空，并且是对象或者是
	  if (obj && typeof obj === "object") {
		for (let key in obj) {
		  if (obj.hasOwnProperty(key)) {
			if (obj[key] && typeof obj[key] === "object") {
			  objClone[key] = this.deep(obj[key]);
			} else {
			  objClone[key] = obj[key];
			}
		  }
		}
	  }
	  return objClone;
	},
  warning :function(vue,text) {
    vue.$message({
      message: text,
      type: 'warning'
    });
  },
  success :function(vue,text) {
    vue.$message({
      message: text,
      type: 'success'
    });
  },
  error :function(vue,text) {
    vue.$message.error(text);
  },
  info :function(vue,text) {
    vue.$message({
      message: text,
      type: 'info'
    });
  },
  /**
 * @copyright chuzhixin 1204505056@qq.com
 * @description 判读是否为外链
 * @param path
 * @returns {boolean}
 */
isExternal :function(path) {
  return /^(https?:|mailto:|tel:)/.test(path);
},

/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description 校验密码是否小于6位
 * @param str
 * @returns {boolean}
 */
isPassword :function(str) {
  return str.length >= 6;
},

/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description 判断是否为数字
 * @param value
 * @returns {boolean}
 */
isNumber:function(value) {
  const reg = /^[0-9]*$/;
  return reg.test(value);
},

/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description 判断是否是名称
 * @param value
 * @returns {boolean}
 */
isName :function(value) {
  const reg = /^[\u4e00-\u9fa5a-zA-Z0-9]+$/;
  return reg.test(value);
},

/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description 判断是否为IP
 * @param ip
 * @returns {boolean}
 */
isIP :function(ip) {
  const reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
  return reg.test(ip);
},

/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description 判断是否是传统网站
 * @param url
 * @returns {boolean}
 */
isUrl :function(url) {
  const reg = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/;
  return reg.test(url);
},

/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description 判断是否是小写字母
 * @param str
 * @returns {boolean}
 */
isLowerCase :function(str) {
  const reg = /^[a-z]+$/;
  return reg.test(str);
},

/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description 判断是否是大写字母
 * @param str
 * @returns {boolean}
 */
isUpperCase :function(str) {
  const reg = /^[A-Z]+$/;
  return reg.test(str);
},

/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description 判断是否是大写字母开头
 * @param str
 * @returns {boolean}
 */
isAlphabets :function(str) {
  const reg = /^[A-Za-z]+$/;
  return reg.test(str);
},

/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description 判断是否是字符串
 * @param str
 * @returns {boolean}
 */
isString :function(str) {
  return typeof str === "string" || str instanceof String;
},

/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description 判断是否是数组
 * @param arg
 * @returns {arg is any[]|boolean}
 */
isArray :function(arg) {
  if (typeof Array.isArray === "undefined") {
    return Object.prototype.toString.call(arg) === "[object Array]";
  }
  return Array.isArray(arg);
},

/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description 判断是否是端口号
 * @param str
 * @returns {boolean}
 */
isPort :function(str) {
  const reg = /^([0-9]|[1-9]\d|[1-9]\d{2}|[1-9]\d{3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/;
  return reg.test(str);
},

/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description 判断是否是手机号
 * @param str
 * @returns {boolean}
 */
isPhone :function(str) {
  const reg = /^1\d{10}$/;
  return reg.test(str);
},

/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description 判断是否是身份证号(第二代)
 * @param str
 * @returns {boolean}
 */
isIdCard :function(str) {
  const reg = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
  return reg.test(str);
},

/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description 判断是否是邮箱
 * @param str
 * @returns {boolean}
 */
isEmail :function(str) {
  const reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
  return reg.test(str);
},

/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description 判断是否中文
 * @param str
 * @returns {boolean}
 */
isChina :function(str) {
  const reg = /^[\u4E00-\u9FA5]{2,4}$/;
  return reg.test(str);
},

/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description 判断是否为空
 * @param str
 * @returns {boolean}
 */
isBlank :function(str) {
  return (
    str == null ||
    false ||
    str === "" ||
    str.trim() === "" ||
    str.toLocaleLowerCase().trim() === "null"
  );
},

/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description 判断是否为固话
 * @param str
 * @returns {boolean}
 */
isTel :function(str) {
  const reg = /^(400|800)([0-9\\-]{7,10})|(([0-9]{4}|[0-9]{3})(-| )?)?([0-9]{7,8})((-| |转)*([0-9]{1,4}))?$/;
  return reg.test(str);
},

/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description 判断是否为数字且最多两位小数
 * @param str
 * @returns {boolean}
 */
isNum :function(str) {
  const reg = /^\d+(\.\d{1,2})?$/;
  return reg.test(str);
},

/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description 判断经度 -180.0～+180.0（整数部分为0～180，必须输入1到5位小数）
 * @param str
 * @returns {boolean}
 */
isLongitude :function(str) {
  const reg = /^[-|+]?(0?\d{1,2}\.\d{1,5}|1[0-7]?\d{1}\.\d{1,5}|180\.0{1,5})$/;
  return reg.test(str);
},

/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description 判断纬度 -90.0～+90.0（整数部分为0～90，必须输入1到5位小数）
 * @param str
 * @returns {boolean}
 */
isLatitude :function(str) {
  const reg = /^[-|+]?([0-8]?\d{1}\.\d{1,5}|90\.0{1,5})$/;
  return reg.test(str);
},

/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description rtsp校验，只要有rtsp://
 * @param str
 * @returns {boolean}
 */
isRTSP :function(str) {
  const reg = /^rtsp:\/\/([a-z]{0,10}:.{0,10}@)?(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
  const reg1 = /^rtsp:\/\/([a-z]{0,10}:.{0,10}@)?(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]):[0-9]{1,5}/;
  const reg2 = /^rtsp:\/\/([a-z]{0,10}:.{0,10}@)?(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\//;
  return reg.test(str) || reg1.test(str) || reg2.test(str);
}

}